﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using Sketchial.Business;

namespace Skecthial.UI.Controls
{
    public partial class DragAndDrop : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginHelper helper= new LoginHelper();

            //rpPlace.DataSource = GetFiles("place");
            rpPlace.DataSource = helper.GetObjectsByClass("place");
            rpPlace.DataBind();

            //rpEvent.DataSource = GetFiles("event");
            rpEvent.DataSource = helper.GetObjectsByClass("event");
            rpEvent.DataBind();

            //rpCountry.DataSource = GetFiles("countries");
            rpCountry.DataSource = helper.GetObjectsByClass("countries");
            rpCountry.DataBind();

            //rpActivity.DataSource = GetFiles("activity");
            rpActivity.DataSource = helper.GetObjectsByClass("activity");
            rpActivity.DataBind();

            //rpPeople.DataSource = GetFiles("people");
            rpPeople.DataSource = helper.GetObjectsByClass("people");
            rpPeople.DataBind();

        }

        public void rp1_dataBound(object sender, EventArgs e)
        {

        }

        public DataTable GetFiles(string folder)
        {
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("id");
            dt2.Columns.Add("obj");
            FileInfo fi = new FileInfo(Server.MapPath("~/Objects/" + folder + "/"));
            DirectoryInfo di = fi.Directory;
            FileInfo[] fsi = di.GetFiles();
            int syc = 0;
            //Response.Write("The directory contains the following files and directories:" + di.FullName + "<hr>");
            foreach (FileSystemInfo info in fsi)
            {
                DataRow dr2 = dt2.NewRow();
                dr2[0] = info.Name ;
                dr2[1] = info.Name + "_" + syc;
                dt2.Rows.Add(dr2);
            }

            return dt2;
        }
    }
}